from dotenv import load_dotenv, find_dotenv
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain_community.utilities import SerpAPIWrapper
from langchain.tools import Tool, tool
from langchain import hub


load_dotenv(find_dotenv())

class searp:
    def __init__(self):
        print('__init__')

    def run(self, input: str) -> str:
        return '周杰伦的演唱会是2024-08-16,2024-06-10'

search = searp()
tools = [
    Tool.from_function(
        func=search.run,
        name="Search",
        description="useful for when you need to answer questions about current events"
    ),
]

# 下载一个现有的 Prompt 模板
react_prompt = hub.pull("hwchase17/react")

# 下载一个模板
# self_ask_prompt = hub.pull("hwchase17/self-ask-with-search")
#
# print(self_ask_prompt.template)

print(react_prompt.template)

llm = ChatOpenAI(model_name='deepseek-ai/DeepSeek-V3', temperature=0, seed=23)

# 定义一个 agent: 需要大模型、工具集、和 Prompt 模板
agent = create_react_agent(llm, tools, react_prompt)
# 定义一个执行器：需要 agent对象 和 工具集
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# 执行
agent_executor.invoke({"input": "2024年周杰伦的演唱会星期几"})